<html>
    <head>
        <meta charset="utf-8" />
        <title>Edit Post</title>
        <script src="ckeditor/ckeditor.js"></script>
    </head>
    
    <body>
        <?php
            if (isset($_GET["idPost"]))
                $idPost = $_GET["idPost"];
            else
            {
                  echo '<script type="application/javascript">
                    document.location.href="index.php";
                  </script>';
            }
            if (isset($_GET["page"]))
            {
                if ($_GET["page"] == 1)
                {
                    $requete = "SELECT * FROM message WHERE id_message='" . $idPost . "';";
                    $mysqli = new mysqli("localhost", "root", "root", "forum");
                    if ($response = $mysqli->query($requete))
                    {
                        $array = $response->fetch_assoc();
                        $titre = $array['titre_message'];
                        $contenu = $array['contenu_message'];
                    }
                    echo '<form action="?idPost=' . $idPost . '&page=2" method="post">
							<p>Titre : <input type="text" name="titre" value="' . $titre . '"></input></p>
							<p>Message : <textarea row="10" name="contenu">' . $contenu . '</textarea></p>
                            <script>CKEDITOR.replace(\'contenu\');</script>
							<p><input type="submit" value="OK"></p>
                          </form>';
                }
                else
                {
                    /*Ici faire la requete pour update le champ*/
                    if (isset($_POST) && isset($_POST["titre"]) && isset($_POST["contenu"]))
                    {
                        date_default_timezone_set("Europe/Paris");
                        $titre = $_POST["titre"];
                        $contenu = $_POST["contenu"];
                        $requete = "UPDATE message SET titre_message='" . $titre . "',contenu_message='" . $contenu . "',date_message='" . date("Y-m-d") . "' WHERE id_message='" . $idPost . "';";
                        echo $requete;
                        $mysqli = new mysqli("localhost", "root", "vlvlvl59150", "forum");
                        if ($response = $mysqli->query($requete))
                        {
                          echo '<script type="application/javascript">
                                document.location.href="index.php";
                                </script>';

                        }
                    }
                }
            }
            else
            {
                  echo '<script type="application/javascript">
                    document.location.href="index.php";
                  </script>';

            }

        
        ?>
    </body>
</html>